%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%% This file is part of the book
%%
%% Algorithmic Graph Theory
%% http://code.google.com/p/graph-theory-algorithms-book/
%%
%% Copyright (C) 2009--2011 Minh Van Nguyen <nguyenminh2@gmail.com>
%%
%% See the file COPYING for copying conditions.
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

\documentclass{article}

\usepackage{subfigure}
\usepackage{tikz}
\usepackage{tkz-berge}  %% for drawing combinatorial graphs
\usetikzlibrary{external}
\tikzexternalize{Prim-algorithm-digraph}

\begin{document}

\begin{figure}
\subfigure[Original digraph.]{
\begin{tikzpicture}
[arrowDecorate/.style={->,>=stealth,thick},%
  nodeDecorate/.style={shape=circle,inner sep=1.5pt,draw,thick},%
  scale=0.8]
\scriptsize
%% nodes or vertices
\foreach \nodename/\x/\y in {0/-4/4, 1/0/8, 2/4/4, 3/0/0}
{
  \node (\nodename) at (\x,\y) [nodeDecorate] {\scriptsize$\nodename$};
}
%% edges or lines
\tikzstyle{EdgeStyle}=[->,>=stealth,thick]
\tikzstyle{LabelStyle}=[fill=white]
\foreach \startnode/\endnode/\bend/\weight in {
  0/1/bend left/1, 0/2/bend left/2, 0/3/bend left=0/3,
  1/0/bend left=0/3, 1/2/bend left/2, 1/3/bend left/1,
  2/0/bend left/2, 2/1/bend left=0/1, 2/3/bend left/3,
  3/0/bend left/1, 3/1/bend left/1, 3/2/bend left=0/1}
{
  \Edge[label=$\weight$,style=\bend](\startnode)(\endnode)
}
\end{tikzpicture}
}
%%
%%
\qquad
\subfigure[1st iteration of while loop.]{
\begin{tikzpicture}
[arrowDecorate/.style={->,>=stealth,thick},%
  nodeDecorate/.style={shape=circle,inner sep=1.5pt,draw,thick},%
  scale=0.8]
\scriptsize
%% nodes or vertices
\foreach \nodename/\x/\y in {0/-4/4, 1/0/8, 2/4/4, 3/0/0}
{
  \node (\nodename) at (\x,\y) [nodeDecorate] {\scriptsize$\nodename$};
}
%% light edges or lines
\tikzstyle{EdgeStyle}=[->,>=stealth,thick,color=gray!30]
\tikzstyle{LabelStyle}=[fill=white]
\foreach \startnode/\endnode/\bend/\weight in {
  0/1/bend left/1, 0/2/bend left/2, 0/3/bend left=0/3,
  2/0/bend left/2, 2/1/bend left=0/1, 2/3/bend left/3,
  3/0/bend left/1, 3/1/bend left/1, 3/2/bend left=0/1}
{
  \Edge[label=$\weight$,style=\bend](\startnode)(\endnode)
}
%% dark edges or lines
\tikzstyle{EdgeStyle}=[->,>=stealth,thick]
\foreach \startnode/\endnode/\bend/\weight in {
  1/0/bend left=0/3, 1/2/bend left/2, 1/3/bend left/1}
{
  \Edge[label=$\weight$,style=\bend](\startnode)(\endnode)
}
\end{tikzpicture}
}
%%
%%
\subfigure[2nd iteration of while loop.]{
\begin{tikzpicture}
[arrowDecorate/.style={->,>=stealth,thick},%
  nodeDecorate/.style={shape=circle,inner sep=1.5pt,draw,thick},%
  scale=0.8]
\scriptsize
%% nodes or vertices
\foreach \nodename/\x/\y in {0/-4/4, 1/0/8, 2/4/4, 3/0/0}
{
  \node (\nodename) at (\x,\y) [nodeDecorate] {\scriptsize$\nodename$};
}
%% light edges or lines
\tikzstyle{EdgeStyle}=[->,>=stealth,thick,color=gray!30]
\tikzstyle{LabelStyle}=[fill=white]
\foreach \startnode/\endnode/\bend/\weight in {
  0/1/bend left/1, 0/2/bend left/2, 0/3/bend left=0/3,
  1/0/bend left=0/3, 1/2/bend left/2, 2/0/bend left/2,
  2/1/bend left=0/1, 2/3/bend left/3, 3/1/bend left/1}
{
  \Edge[label=$\weight$,style=\bend](\startnode)(\endnode)
}
%% dark edges or lines
\tikzstyle{EdgeStyle}=[->,>=stealth,thick]
\foreach \startnode/\endnode/\bend/\weight in {
  1/3/bend left/1, 3/0/bend left/1, 3/2/bend left=0/1}
{
  \Edge[label=$\weight$,style=\bend](\startnode)(\endnode)
}
\end{tikzpicture}
}
%%
%%
\qquad
\subfigure[Final MST.]{
\begin{tikzpicture}
[arrowDecorate/.style={->,>=stealth,thick},%
  nodeDecorate/.style={shape=circle,inner sep=1.5pt,draw,thick},%
  scale=0.8]
\scriptsize
%% nodes or vertices
\foreach \nodename/\x/\y in {0/-4/4, 1/0/8, 2/4/4, 3/0/0}
{
  \node (\nodename) at (\x,\y) [nodeDecorate] {\scriptsize$\nodename$};
}
%% edges or lines
\tikzstyle{EdgeStyle}=[->,>=stealth,thick]
\tikzstyle{LabelStyle}=[fill=white]
\foreach \startnode/\endnode/\bend/\weight in {
  1/3/bend left/1, 3/0/bend left/1, 3/2/bend left=0/1}
{
  \Edge[label=$\weight$,style=\bend](\startnode)(\endnode)
}
\end{tikzpicture}
}
\end{figure}

\end{document}
